<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="WHIT">
<span class='line'>  2</span> </span><span class="COMM">/**
<span class='line'>  3</span>  * @fileoverview Miscellaneous files utility methods.
<span class='line'>  4</span>  * @link http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
<span class='line'>  5</span>  * @link https://developers.google.com/closure/compiler/docs/js-for-compiler
<span class='line'>  6</span>  */</span><span class="WHIT">
<span class='line'>  7</span> 
<span class='line'>  8</span> 
<span class='line'>  9</span> 
<span class='line'> 10</span> </span><span class="COMM">/**
<span class='line'> 11</span>  * Miscellaneous files utility methods.
<span class='line'> 12</span>  * @constructor
<span class='line'> 13</span>  */</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="NAME">util.FileUtils</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 15</span> 
<span class='line'> 16</span> 
<span class='line'> 17</span> </span><span class="COMM">/**
<span class='line'> 18</span>  * @param {string} data Data content.
<span class='line'> 19</span>  * @param {string=} opt_fileName Optional file name.
<span class='line'> 20</span>  * @param {string=} opt_contentType Optional content type.
<span class='line'> 21</span>  * @static
<span class='line'> 22</span>  */</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="NAME">util.FileUtils.saveAs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_fileName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_contentType</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="WHIT">  </span><span class="COMM">/** @type {Element} */</span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">link</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">dom.createElement</span><span class="PUNC">(</span><span class="STRN">'A'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="WHIT">  </span><span class="NAME">opt_fileName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">opt_fileName</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">'file'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="WHIT">  </span><span class="NAME">opt_contentType</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">opt_contentType</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="STRN">'text/plain'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">window.Blob</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="STRN">'download'</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">link</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT">    </span><span class="NAME">link</span><span class="PUNC">[</span><span class="STRN">'href'</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">window.URL</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.webkitURL</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">createObjectURL</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'> 29</span> </span><span class="WHIT">        </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Blob</span><span class="PUNC">(</span><span class="PUNC">[</span><span class="NAME">data</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="WHIT">        </span><span class="PUNC">{</span><span class="STRN">'type'</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">opt_contentType</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">';charset='</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">dom.CHARSET</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="WHIT">    </span><span class="NAME">link.setAttribute</span><span class="PUNC">(</span><span class="STRN">'download'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_fileName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT">    </span><span class="NAME">dom.document.body.appendChild</span><span class="PUNC">(</span><span class="NAME">link</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">    </span><span class="NAME">link.click</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">    </span><span class="COMM">// @link http://msdn.microsoft.com/en-us/library/cc848897(VS.85).aspx</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">    </span><span class="NAME">window.open</span><span class="PUNC">(</span><span class="STRN">'data:'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">opt_contentType</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="WHIT">                </span><span class="STRN">';base64,'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">util.StringUtils.Base64.encode</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 40</span> </span></pre></body></html>